<?php

// +----------------------------------------------------------------------
// | Apprh.Shop
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.apprh.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// +----------------------------------------------------------------------
// | Author: pp <124910168@qq.com>
// +----------------------------------------------------------------------

namespace app\home\controller;

use controller\BasicHome;
use think\Db;
// use think\Controller;

/**
 * 首页
 * Class Index
 * @package app\home\controller
 * @author pp <124910168@qq.com>
 * @date 2020/08/15 10:41
 */
class Index extends BasicHome
{
    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {
        $characteristics = $this->characteristic->getLists(['status' => 1]);
        $clients = $this->client->getLists(['status' => 1, 'is_deleted' => '0']);
        $clinics = $this->clinic->getLists(['status' => 1]);
        // $cates = $this->category->getColumn(['id' => ['in', '1,2,3,4,5']], 'id,catname,moduleid,module');
        // $coursewares = $this->article->getLists(['status' => 1, 'catid' => ['in', '1,2,3,4,5']]);
        $prescriptions = $this->prescription->getLists(['status' => 1]);
        $demonstrations = $this->demonstration->getLists(['status' => 1]);
        $drugs = $this->drug->getLists(['status' => 1]);
        $news = $this->article->getLists(['status' => 1, 'catid' => 6], 'id desc');
        $coursewares = [];
        foreach ($this->coCates as $k => $v) {
            $items = Db::name($v['module'])->where(['catid' => $v['id'], 'status' => 1])->select();
            if($items){
                $coursewares = array_merge($coursewares, $items);
            }
        }
        shuffle($coursewares);
        foreach ($clients as $k => $v) {
            $clients[$k]['honors'] = $clients[$k]['honor'] ? explode("\r\n", $v['honor']) : [];
            $clients[$k]['advantages'] = $clients[$k]['advantage'] ? explode("\r\n", $v['advantage']) : [];
            $clients[$k]['id_imagess'] = $clients[$k]['id_images'] ? explode(",", $v['id_images']) : [];
            $clients[$k]['cert_imagess'] = $clients[$k]['cert_images'] ? explode(",", $v['cert_images']) : [];
        }
        // halt($news);
        $data = [
            'characteristics' => $characteristics,
            'clients' => $clients,
            'clinics' => $clinics,
            'coursewares' => $coursewares,
            'prescriptions' => $prescriptions,
            'demonstrations' => $demonstrations,
            'drugs' => $drugs,
            'news' => $news,
        ];
        return $this->fetch('', $data);
    }

}
